<script>
import Vue from 'vue'
import { exportDefault } from '@/utils/index'

export default {
  props: {
    htmlCode: {
      type: String,
      required: false,
      default: ''
    },
    jsCode: {
      type: String,
      required: false,
      default: ''
    },
    compId: {
      type: String,
      required: true,
      default: ''
    }
  },
  data() {
    return {
    }
  },
  mounted() {
    this.$emit('afterMounted')
  },
  beforeCreate() {
    // this.$options.components[this.compId] = this.vueCode
  },
  /* eslint-disable */
  render: function(h) {
    const componentId = 'dynamic' + this.compId
    const jscode = this.jsCode ? this.jsCode.replace(exportDefault, '') : ''
    const main = jscode ? eval(`(${jscode})`) : {} // eval(`()`)
    main.template = `<div>${this.htmlCode}</div>`
    Vue.component(componentId, main)
    /* Vue.component(componentId, {
      components: {
        child: main
      },
      data() {
        return {
          visible: true
        }
      },
      template: `<div><child /></div>`
    })*/
    return h(componentId)
  }
}
</script>
